﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using ModuleDALCore;
using System.Data;

namespace DAL
{
    public class NGHENGHIEPDAO:DALBase
    {

        public NGHENGHIEPDAO()
        {
            this.OpenConnect();
        }
        private DataTable dt;
        private string _SpName;

        public string SpName
        {
            get { return "SPNGHENGHIEP"; }
            set { _SpName = value; }
        }
        public DataTable GetListNN()
        {
            dt = new DataTable();
            try
            {

                dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new NGHENGHIEP(), null), ConvertClassToArray.GetValues(new NGHENGHIEP(), 0));
                return dt;
            }
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list NN"); }
        }
		public List<NGHENGHIEP> GetListNNL()
		{
			dt = new DataTable();
			List<NGHENGHIEP> dsnn = new List<NGHENGHIEP>();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(new NGHENGHIEP(), null), ConvertClassToArray.GetValues(new NGHENGHIEP(), 0));
				dsnn = (List<NGHENGHIEP>)ConvertDatatableToList.ConvertTo<NGHENGHIEP>(dt);
			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list NN"); }
			return dsnn;
		}
		public List<NGHENGHIEP> GetListNNByID(NGHENGHIEP ngh)
		{
			dt = new DataTable();
			List<NGHENGHIEP> dsnn = new List<NGHENGHIEP>();
			try
			{

				dt = DBManager.Intance.ExecuteDataTable(SpName, ConvertClassToArray.GetParamName(ngh, null), ConvertClassToArray.GetValues(ngh, 5));
				dsnn = (List<NGHENGHIEP>) ConvertDatatableToList.ConvertTo<NGHENGHIEP>(dt);
			}
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't list NN"); }
			return dsnn;
		}
        public String CreatenewId()
        {
            try
            {
                return "NN" + DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(new NGHENGHIEP(), null), ConvertClassToArray.GetValues(new NGHENGHIEP(), 1));

            }
			catch { return null; }//throw new InvalidExpressionException("Msg1: Can't Create new NN"); }
        }
        public bool INSERT(NGHENGHIEP cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 2)) == 1);

            }
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Insert new NN"); }
        }
        public bool UPDATE(NGHENGHIEP cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 3)) == 1);

            }
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Update  NN"); }
        }
        public bool DELETE(NGHENGHIEP cv)
        {

            try
            {
                return (DBManager.Intance.ExecuteNonQuery(SpName, ConvertClassToArray.GetParamName(cv, null), ConvertClassToArray.GetValues(cv, 4)) == 1);

            }
			catch { return false; }//throw new InvalidExpressionException("Msg1: Can't Delete  NN"); }
        }
    }
}
